import pymysql


def main():
    no = input('请输入部门编号：')
    loc = input('请输入部门新的所在地')
    conn = pymysql.connect(host='192.168.3.11', port=3306, user='root', password='123', db='hrs', charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute('update tb_dept set dloc=%s where dno=%s;',(loc,no))
            print(result)
            if result == 1:
                print('添加成功')
            conn.commit()
    except pymysql.MySQLError as error:
        print(error,'添加失败')
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
